package com.star.spring.websocket.component;

import com.star.spring.websocket.client.WebSocketClientHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class WebSocketClientAutoConnect implements CommandLineRunner {

    @Autowired
    private WebSocketClientHandler webSocketClientHandler;

    @Override
    public void run(String... args) throws Exception {
        log.info("应用启动完成，开始连接WebSocket客户端...");
        
        // 延迟3秒后连接，确保服务器完全启动
        Thread.sleep(3000);
        
        webSocketClientHandler.connect();
        
        log.info("WebSocket客户端连接请求已发送");
    }
} 